//==============================================================================
// CLibraryAdditions.cc
//----------------------------------------------------------------------------
// Functions that mirror C library functions. 
//
//
//------------------------------------------------------------------------------
// $Id: CLibraryAdditions.cc,v 1.1 2000/03/31 19:32:26 kdurbin Exp kdurbin $
//------------------------------------------------------------------------------
// $Log: CLibraryAdditions.cc,v $
// Revision 1.1  2000/03/31 19:32:26  kdurbin
// Initial revision
//
//   
//==============================================================================
//.......1.........2.........3.........4.........5.........6.........7.........8
//

#include "CLibraryAdditions.hh"

char readbuf[READ_BUFFER_SIZE];


//---------------------------------------------------------------------------
// * itoa
//---------------------------------------------------------------------------
//
//
string itoa(int num)
{
  char buf[STRING_BUFFER_SIZE];
  sprintf(buf,"%d",num);
  string temp = buf;
  return(temp);
}

//---------------------------------------------------------------------------
// * ftoa
//---------------------------------------------------------------------------
//
string ftoa(float num)
{
  char buf[STRING_BUFFER_SIZE];
  sprintf(buf,"%f",num);
  string temp = buf;
  return(temp);
}


//---------------------------------------------------------------------------
// * ftoa
//---------------------------------------------------------------------------
//
string ftoa(float num,string fmt)
{
  char buf[STRING_BUFFER_SIZE];
  sprintf(buf,fmt.c_str(),num);
  string temp = buf;
  return(temp);
}


//---------------------------------------------------------------------------
// * itostring
//---------------------------------------------------------------------------
//
//
string itostring(int num)
{
  char buf[STRING_BUFFER_SIZE];
  sprintf(buf,"%d",num);
  string temp = buf;
  return(temp);
}

//---------------------------------------------------------------------------
// * ftostring
//---------------------------------------------------------------------------
// Ditto.   
//
string ftostring(float num)
{
  char buf[STRING_BUFFER_SIZE];
  sprintf(buf,"%f",num);
  string temp = buf;
  return(temp);
}

//---------------------------------------------------------------------------
// * atoi
//---------------------------------------------------------------------------
//
int atoi(string &s)
{
  int val = atoi(s.c_str());
  return(val);
}


//---------------------------------------------------------------------------
// * sprintf
//---------------------------------------------------------------------------
// String version of sprintf
//
void sprintf(int MaxSize,string &outString,const char*fmt,...)
{
  va_list argp;
  
  // Maybe someday I'll write a version that figures out the size 
  // and expands the buffer automatically.
  int fmtSize = strlen(fmt);
  char *buf = new char[MaxSize];

  // Tell va mechanism what the last -named- argument is
  va_start(argp,fmt);
  vsprintf(buf,fmt,argp);
  outString = buf;
  delete buf;
}

//---------------------------------------------------------------------------
// * GetLine
//---------------------------------------------------------------------------
// getline is supposed to be builtin C++ standard library stuff, but some
// compilers are so lame that they don't implement this correctly. Obviously
// this is limited by READ_BUFFER_SIZE, which is set to something like 64K. 
//
bool GetLine(istream &theFile,string &theLine)
{
  bool status = theFile.getline(readbuf,READ_BUFFER_SIZE);
  theLine = readbuf;
  return(status);
}





